package cn.zhaoguang.usedcar.main.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.zhaoguang.usedcar.main.entity.Collection;
import cn.zhaoguang.usedcar.main.entity.dto.CollectionDTO;
import cn.zhaoguang.usedcar.main.mapper.CollectionMapper;
import cn.zhaoguang.usedcar.main.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author zhaoguang
 * @Date 2021/7/5 22:03
 */
@Service
public class CollectionServiceImpl implements CollectionService {

    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public int add(Collection collection) {
        collection.setOperationTime(DateUtil.date());
        return collectionMapper.save(collection);
    }

    @Override
    public int delete(Integer id) {
        return collectionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer findCollectionByUserId(Integer userId, Integer usedcarId) {
        return collectionMapper.findCollectionByUserId(userId, usedcarId);
    }

    @Override
    public List<CollectionDTO> findAll(Integer userId) {
        return collectionMapper.findAll(userId);
    }
}
